package cloudoer.blog.controller;

import cloudoer.blog.base.BaseController;
import cloudoer.blog.entity.User;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class AdminController extends BaseController {
    private static Logger logger = Logger.getLogger(AdminController.class);

    @RequestMapping("/adminIndex")
    public String index(){
        return "admin/index/index";
    }

    @RequestMapping("/login")
    public String login(User user,HttpServletRequest request){
        User u = userService.login(user);
        if (u != null){
            if ("admin".equals(u.getState())){
                request.getSession().setAttribute("admin", u);
                return "redirect:/adminIndex.action";
            }
        }
        return "redirect:admin/login.action";
    }
}
